// api/data_api/statistic.go
package data_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/utils/res"
)

type StatisticResponse struct {
	UserCount     int64 `json:"userCount"`
	RoleCount     int64 `json:"roleCount"`
	ChatCount     int64 `json:"chatCount"`
	NowChatCount  int64 `json:"nowChatCount"`
	NowLoginCount int64 `json:"nowLoginCount"`
}

func (DataApi) StatisticView(c *gin.Context) {
	var data StatisticResponse

	global.DB.Model(models.UserModel{}).Count(&data.UserCount)
	global.DB.Model(models.AiRoleModel{}).Where("is_square = 1").Count(&data.RoleCount)
	global.DB.Model(models.ChatModel{}).Count(&data.ChatCount)
	global.DB.Model(models.ChatModel{}).Where("date(created_at) = date (now())").Count(&data.NowChatCount)
	global.DB.Model(models.UserLoginModel{}).Where("date(created_at) = date (now())").Count(&data.NowLoginCount)

	res.OkWithData(c, data)
}
